package com.basemanage.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import com.basemanage.core.model.Condition;
import com.basemanage.core.model.Operators;
import com.basemanage.core.view.InvokeResult;
import com.basemanage.model.SmOrderbar;
import com.basemanage.model.base.BaseSmOrderbar;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings("serial")
public class OrderbarService extends BaseSmOrderbar<SmOrderbar> {

	public static final SmOrderbar dao = new SmOrderbar();

	public static final OrderbarService me = new OrderbarService();
	
	/**
	 * 保存/更新
	 * @param wxUser
	 * @return
	 */
	public InvokeResult saveOrderbar(SmOrderbar orderbar) {
		if (orderbar.getInt("id") != null) {
//			orderbar.setUpdateTime(new Date());
			orderbar.update();
		} else {
//			orderbar.setCreateTime(new Date());
			orderbar.save();
		}
		return InvokeResult.success();
	}

	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	public InvokeResult delOrderbar(String ids) {
		List<Integer> idsList = new ArrayList<Integer>();

		for (String idstr : ids.split(",")) {

			if (StrKit.isBlank(idstr))
				continue;

			idsList.add(Integer.valueOf(idstr));
		}

		Set<Condition> conditions = new HashSet<Condition>();
		conditions.add(new Condition("id", Operators.IN, idsList));
		dao.delete(conditions);

		return InvokeResult.success();
	}


	/**
	 * 列表显示
	 * @param ids
	 * @return
	 */
	public Page<SmOrderbar> getPage(int page, int rows, LinkedHashMap<String, String> orderby) {
		return dao.getPage(page, rows,orderby);
	}


}